# 31. 学生排名
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let lineCount = 1;
let subCount = 0;
let stuCount = 0;
let subArr = [];
let k;
let ans = [];
rl.on('line', function(line) {
if (lineCount === 1) {
stuCount = line.split(' ').map(Number)[0];
subCount = line.split(' ').map(Number)[1];
} else if (lineCount === 2) {
subArr = line.split(' ');
} else if (lineCount === 3 + stuCount) {
k = line;
} else {
let arr = line.split(' ');
let obj = {};
let all = 0;
for(let i=0;i<arr.length;i++) {
if (i===0) {
obj.name = arr[i];
} else {
obj[subArr[i - 1]] = parseInt(arr[i]);
all+=parseInt(arr[i]);
}
}
obj.all = all;
ans.push(obj);
}
lineCount++;
})
rl.on('close', function() {
ans.sort((a, b) => {
let a1 = k ? a[k] : a.all;
let b1 = k ? b[k] : b.all;
if (a1 != b1) {
return b1 - a1;
} else {
a.name - b.name;
}
});
let str = '';
ans.forEach((item, index) => {
if (index !== ans.length - 1) {
str += (item.name + ' ')
} else {
str += item.name;
}
});
console.log(str);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57